@extends('layouts.app')
@section('content')
    <div class="content">
        <div class="row custom-invoice">
            <div class="row">
                <form method="get" action="{{ route('admin.package.lib') }}">
                    <input type="hidden" name="attr" value="{{ $attr }}">
                    <div class="form-group col-md-3 col-sm-6 col-xs-10" style="width:300px">
                        <input class="form-control" type="text" name="name" value="{{ $name }}" placeholder="产品名">
                    </div>
{{--                    <div class="form-group col-md-3 col-sm-6 col-xs-10" style="width:300px">--}}
{{--                        <input class="form-control" type="text" name="type" value="{{ $type }}" placeholder="类别">--}}
{{--                    </div>--}}
                    <div class="form-group col-md-2 col-sm-10 col-xs-10" style="width:100px">
                        <button class="btn btn-success btn-ms" type="submit">搜索</button>
                    </div>
                </form>
            </div>
            @can('package-edit')
            <a class="btn btn-success" href="{{ route("admin.package.lib.create", ['attr' => $attr]) }}">添加产品</a>
            @endcan
            <br />
            <br />
            <table class="table table-striped table-hover" width="1000">
                <thead>
                <tr>
                    <th>封面</th>
                    <th>类别
                        <a href="{{ route('admin.package.lib', ['name' => $name, 'type' => $type, 'field' => 'name', 'sort' => ($sort == 'asc'?'desc':'asc')]) }}">
                            <i class="fa {{ $field == "name"?($sort == 'asc'? "fa-sort-asc":"fa-sort-desc"): 'fa-sort'}}"></i>
                        </a>
                    </th>
                    <th>产品 <a href="{{ route('admin.package.lib', ['name' => $name, 'type' => $type, 'field' => 'value', 'sort' => ($sort == 'asc'?'desc':'asc')]) }}">
                            <i class="fa {{ $field == "value"?($sort == 'asc'? "fa-sort-asc":"fa-sort-desc"): 'fa-sort'}}"></i>
                        </a>
                    </th>
                    <th>价格 <a href="{{ route('admin.package.lib', ['name' => $name, 'type' => $type, 'field' => 'price', 'sort' => ($sort == 'asc'?'desc':'asc')]) }}">
                            <i class="fa {{ $field == "price"?($sort == 'asc'? "fa-sort-asc":"fa-sort-desc"): 'fa-sort'}}"></i>
                        </a>
                    </th>
                    <th>折扣(%) <a href="{{ route('admin.package.lib', ['name' => $name, 'type' => $type, 'field' => 'discount', 'sort' => ($sort == 'asc'?'desc':'asc')]) }}">
                            <i class="fa {{ $field == "discount"?($sort == 'asc'? "fa-sort-asc":"fa-sort-desc"): 'fa-sort'}}"></i>
                        </a></th>
                    <th>操作</th>
{{--                    <th>排序权重</th>--}}
                </tr>
                </thead>
                <tbody>
                @foreach($value as $item)
                    <tr>
                        <td>
                           <img src="{{ \App\Library\OSS::instance()->getUrl($item->cover) }}" width="100">
                        </td>
                        <td>{{ $item->name }}</td>
                        <td>{{ $item->value }}</td>
                        <td>{{ $item->price/100 }}</td>
                        <td>{{ $item->discount }}</td>
                        <td>
                            @can('package-edit')
                            <a class="btn btn-primary btn-xs" href="{{ route('admin.package.lib.edit', ['id' => $item->id]) }}"><i class="fa fa-edit"></i> 编辑</a>
                            <a class="btn btn-danger btn-xs delete-confirm" data-href="{{ route('admin.package.lib.delete', ['id' => $item->id]) }}"><i class="fa fa-trash-o"></i> 删除</a>
                            @endcan
                        </td>
{{--                        <td>--}}
{{--                            <input type="text" class="col-xs-3 change-sort" data-id="{{ $item->id }}" value="{{ $item->sort }}" />--}}
{{--                        </td>--}}
                    </tr>
                @endforeach
                </tbody>
            </table>
            {{ $value->appends(['name' => $name, 'type' => $type, 'attr' => $attr])->links() }}
        </div>
    </div>
@endsection
@push('scripts')
    <script>
        $('.change-sort').on('change', function () {
            var sort = $(this).val();
            var id = $(this).attr('data-id');
            $.ajax({
                url: '{{ route('admin.package.lib.sort') }}',
                type: "GET",
                dataType:'json',
                data: {
                    id: id,
                    sort: sort,
                },
                success: function (re) {
                }
            });
        });

    </script>
@endpush
